package cn.org.cute.ebocy.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
 * 数据解压方法工具类
 * @Copyright©2011, 2011 EBO CHANGYOU Co.td. All rights reserved.
 * @Version 1.0.0
 * @since jdk1.6
 * @author xiaolei
 * @date 2011-12-6
 */
public class DateDecompress {

	/**
	 * 用unzip解压数据 
	 * @param unzipCompressed 需要解压的原始数据
	 * @return
	 */
    public static Object doUnZip(byte[] unzipCompressed) {   
        if (unzipCompressed == null)  return null;  
  
        ByteArrayOutputStream out = null;  
        ByteArrayInputStream in = null;  
        ZipInputStream zin = null;  
        Object decompressed;  
        try {  
            out = new ByteArrayOutputStream();  
            in = new ByteArrayInputStream(unzipCompressed);  
            zin = new ZipInputStream(in);  
            ZipEntry entry = zin.getNextEntry();  
            byte[] buffer = new byte[1024];  
            int offset = -1;  
            while ((offset = zin.read(buffer)) != -1) {  
                out.write(buffer, 0, offset);  
            }  
              
            decompressed = ByteToObjectUtil.byteToObject(out.toByteArray());  
        } catch (Exception e) {  
            e.printStackTrace();  
            decompressed = null;  
        } finally {  
            if (zin != null) {  
                try {  
                    zin.close();  
                } catch (IOException e) {  
                }  
            }  
            if (in != null) {  
                try {  
                    in.close();  
                } catch (IOException e) {  
                }  
            }  
            if (out != null) {  
                try {  
                    out.close();  
                } catch (IOException e) {  
                }  
            }  
        }  
        return decompressed;  
    }  
	
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
